<?php 
defined("AT_EXE") or die ("CORE VARIABLE IS NOT DEFINED.");
class ResumeController extends controller{
	private $emp_session ;
	private $can_session;
	public function __construct(){
		$this->calledClass(get_class($this));
		$this->emp_session = Session::get("employer");
		$this->can_session = Session::get("candidate");
	}

	public function admin(){
		$this->setLevel(3);
	}
	public function checkBasicInfo(){
		$help = true;
		$resume = $this->loadModel("Resume");
		$record = $resume->findAsObject(array("can_id="=>$this->can_session["id"]));
		if(is_object($record)){
			if($record->rem_name=="" || $record->rem_name==NUll ){
				$help=false;
			}
			if($record->rem_DOB=="" || $record->rem_DOB==NUll || $record->rem_DOB =='0000-00-00' ){
				$help=false;
			}
			if($record->rem_email=="" || $record->rem_email==NUll ){
				$help=false;
			}
			if($record->rem_tel=="" || $record->rem_tel==NUll ){
				$help=false;
			}
			if($record->rem_attach=="" || $record->rem_attach==NUll ){
				$help=false;
			}
			if($record->rem_uploadImg=="" || $record->rem_uploadImg==NUll ){
				$help=false;
			}
			if($record->rem_nationalitys=="" || $record->rem_nationalitys==NUll ){
				$help=false;
			}
		}else{
			$help = false;
		}
		return $help;
	}
	/*
	* @Developer: Mr Roth and Sidet
	* @Create Date: 2-April-2014
	* @Return check field in resume OR apply job successfull
	* */
	public function application(){
		// to do task
		// check Basic information if all requirement is completed
		$checkFieldResume=$this->checkBasicInfo();
		if($checkFieldResume==false){
			$this->refresh(array("resume"=>"editcv"),array(),6);
			echo "required" ;
		}elseif($checkFieldResume==true) {
			/* apply job */
			$this->applyPage();
		}
		// then process send application
		// if not completed Basic information then redirect user to resume's page
	}

	/*
		* @Developer: Mr Roth and Sidet
	* @Create Date: 2-April-2014
	* @Return infomation of Employer
	* */
	public function getInfoEmployer($jid){
		$candidate=$this->loadModel("Candidate");
		$recordEmp=$candidate->getRecordSendMail($jid);
		return $recordEmp;
	}
	public function unapply(){
		$apply = $this->loadModel("NotiApplie");
		//remove update status off notiapply to 0 when candidate click on unapply job
		$apply->delete(array("id="=>$this->get("id")));
	}
	
	/*
		* @Developer: Mr Roth and Sidet
	* @Create Date: 2-April-2014
	* @Return send email for Employer and Candidate
	* */
	public function applyPage(){
		$this->set(array("layout"=>"applyjob"));
		$candidate=$this->loadModel("Candidate");
		$apply=$this->loadModel("NotiApplie");
		$resume = $this->loadModel("Resume");
		$job = $this->loadModel("Job");
		$gallery=$this->loadModel("Gallery");
		$cv_can_gal=$resume->viewCV($this->can_session["id"]);
		$get_job_id = $job->findObject(array("id="=>$this->get("id")));
		//find attachment file of candidate to attach in email
		$attachment = $gallery->findObject(array("id="=>$cv_can_gal->rem_attach));
		if(!is_object($cv_can_gal)){
			$this->refresh(array("candidate"=>"adminjob"),array(),3);
			//echo "There is an error with applying job, please try to contact the administrator, you will be redirected to the Job's page within 3 seconds." ;
			echo "timeout";
		}else{
			/* starting  save apply ready job  */
			$postid=$apply->getCompApplyID($this->get("id"),$this->can_session["id"]);
			$canid=$apply->getCandidatid($this->can_session["id"]);
			if($postid==$this->get("id") && $canid==$this->can_session["id"]){
				$this->refresh(array("candidate"=>"adminjob"),array(),3);
				//echo "<div style='color:#3E4095;font-size:15px;margin:0 auto;'>Job has been apply already !, you will be redirected to the Job's page within 3 seconds.</div>";
				echo "already";
			}
			/* ending of save apply ready job  */
			else{
				$username=ucfirst($cv_can_gal->can_id->firstname." ".$cv_can_gal->can_id->lastname);
				$candidate_email= $cv_can_gal->can_id->email;
				// block all contact information of candidate to employer
				// next step of project HRCambodia, system will provide a communication between candidate and employer on the system.
				//$cvPhone=$cv_can_gal->rem_tel;
				//$cvAddress=$cv_can_gal->rem_add;
				$emp_job=$this->getInfoEmployer($this->get("id"));
				$employer_email=$emp_job->email ;
				/* $photo=$this->upload(); */
				$str = "<b>HRCambodia.com Alert Apply Job Information</b><br/>";
				$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Name : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . $username ."</span><br/>";
				//	$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Phone : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . $cvPhone ."</span><br/>";
				//	$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Address : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . $cvAddress ."</span><br/>";
				//	$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Email : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . $email ."</span><br/>";
				$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Apply Date : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . date("d-m-Y ") ."</span><br/>";
				$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Title : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . $emp_job->title ."</span><br/>";
				$str .="<span style='font-family: Trebuchet MS;padding-right:5px'>Post Date : </span><span style='font-family: Trebuchet MS;padding-right:5px;font-weight:bold'>" . $emp_job->start_date ."</span><br/>";
				//send mail to employer after updated status
				ob_start();
				//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
				Import::util('class.phpmailer');
				//the true param means it will throw exceptions on errors, which we need to catch
				$mail = new PHPMailer(true);
				//telling the class to use SMTP
				$mail->IsSMTP();
				try {
					// SMTP server
					$mail->Host = "mail.hrcambodia.com";
					// enables SMTP debug information (for testing),  show debug : SMTPDebug  = 2,  Hide debug : SMTPDebug  = 1
					$mail->SMTPDebug = 1;
					// enable SMTP authentication
					$mail->SMTPAuth = true;
					// set the SMTP port for the MY OWN DOMAIN server
					$mail->Port = 26;
					// SMTP account username
					$mail->Username = "noreply@hrcambodia.com";
					// SMTP account password
					$mail->Password = "pwd*123456";
					$email_address = filter_input(INPUT_GET,$employer_email, FILTER_VALIDATE_EMAIL);
					if (!$email_address) {
						/* starting of  save apply job  */
						$return = $apply->save(array("job_id"=>$this->get("id"),"can_id"=>$this->can_session["id"],"date_apply"=>date("Y-m-d H:i:s")));
						/* ending of save apply job  */
						$mail->SetFrom("noreply@hrcambodia.com", 'HRCambodia.com');
						if($get_job_id->email!=""){
							//send mail to email of job post
							$mail->AddAddress($get_job_id->email,$get_job_id->email);
						}else{
							//send mail to employer 
							$mail->AddAddress($employer_email,$employer_email);
						}
						$mail->AddAddress($candidate_email,$candidate_email); // add candidate email 
						
						$mail->AddReplyTo("admin@hrcambodia.com","HRCambodia.com");
						$mail->Subject ='Job Applied, posted your ads from HRCambodia.com as '.$emp_job->title;
						// optional - MsgHTML will create an alternate automatically
						$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
						//if candiadte has attachment file will attach with mail 
						if(Basic::fileExist($attachment->location)){
							$mail->AddAttachment($attachment->location,$attachment->name,"base64",$attachment->type);
						}
						$link = "Please <a href='".SERVER.$this->getPath(array('resume'=>'detailcandidat'),array('pid'=>$cv_can_gal->id,"appid"=>$return->id,'empapp'=>'empapp','view_cv'=>'fullview','emp'=>$get_job_id->user_id))."'>Click Here</a> to view candidate detail on <a href='http://www.hrcambodia.com/'>www.hrambodia.com</a>";
						$str.="<br />".$link;
						// no attachment file send link to view resume of that candidate.
						$mail->MsgHTML($str);
						$mail->Send();
					} else {
						//echo 'Email is invalid...';
						break;
					}
				} catch (phpmailerException $e) {
					//Pretty error messages from PHPMailer
					echo $e->errorMessage();
				} catch (Exception $e) {
					//Boring error messages from anything else!
					echo $e->getMessage();
				}
				// }
				$this->refresh(array("candidate"=>"adminjob"),array(),3);
				//echo "<div style='color:#3E4095;font-size:15px;margin:0 auto;'>Job has been apply successfully !, you will be redirected to the Job's page within 3 seconds.</div>";
				echo "success";
			}
		}
		//$this->render("apply");
	}

	public function main(){
		$resume = $this->LoadModel("Resume");
		$gallery= $this->loadModel("Gallery");
		$category= $this->loadModel("Categorie");
		$this->set(array("row"=>$resume->findArray(array("can_id="=>$this->get("id")))));
		$this->set(array("Select"=>$category->SelectQu(143)));
		$this->set(array("SelectY"=>$category->SelectQu(333)));
		$this->set(array("gallery"=>$gallery->findArray(array("uid="=>$this->get("id")))));
		$this->render("viewCV");
	}

	public function upattachment(){
		$this->render("uploadattachment");
	}

	public function display(){
		//$user = $this->loadModel("UserC");
		//$this->set(array("list"=>$user->getList(1,5,"",array("username"))));
		//$this->set(array("list"=>$user->getList($this->get("page"),5,$this->get("search"),array("username"))));
		$this->layout = "display";
		$this->render();
	}

	public function cv(){
		//echo $this->get("locations").$this->get("education").$this->get("province").$this->get("experience");
		$cv = $this->loadModel("Resume");
		$this->set(array("Location"=>$cv->SelectQu(1)));
		$this->set(array("Education"=>$cv->SelectQu(138)));
		$this->set(array("Experience"=>$cv->SelectQu(133)));
		$this->set(array("National"=>$cv->SelectQu(34)));
		$this->set(array("Province"=>$cv->SelectQu(99)));
		//$records = $condidate->getList($page=1,$perpage=20,$search="",$searchFields=array(),$sortFields=array(),$sortCriteria="");
		$records = $cv->getList(
				$this->get("page"),
				$this->get("perpage"),
				$this->get("searches"),
				array("rem_name","rem_email","rem_salary","rem_position","firstname","lastname"),
				array("id"),
				"ASC",
				array("rem_location="=>$this->get("locations"),
						"rem_educate="=>$this->get("education"),
						"rem_province="=>$this->get("province"),
						"rem_experience_y="=>$this->get("experience"),
						"rem_city="=>$this->get("city"),
						"rem_country="=>$this->get("country")
				)
		);
		$this->set(array("records"=>$records));
		$this->set(array("current_menu"=>"cv"));
		$this->set(array("l"=>$this->get("locations"),
				"e"=>$this->get("education"),
				"p"=>$this->get("province"),
				"ex"=>$this->get("experience"),
				"ct"=>$this->get("city"),
				"c"=>$this->get("country")));
		$this->render("admin_display");
	}

	public function addNew(){
		$resumes = $this->loadModel("Resume");
		$this->set(array("SelectY"=>$resumes->SelectQu(333)));
		$this->set(array("Select"=>$resumes->SelectQu(143)));
		$this->set(array("Location"=>$resumes->SelectQu(1)));
		$this->set(array("Position"=>$resumes->SelectQu(137)));
		$this->set(array("Postcode"=>$resumes->SelectQu(180)));
		$this->set(array("category"=>$resumes->SelectQu(23)));
		/*$records=$this->upload(5);*/
		/*if(isset($_POST["btnsave"])){*/
		$data = $resumes->version("Resumes","rem_hit",array("can_id="=>$this->get("id")));
		$version = $data + 1;
		$record=$this->upload($this->can_session["id"],"data/cv/",5);
		$candidad = $this->get("id");
		$resumes->edit(array(
				"rem_uploadImg"=>$record[0],
				"can_id"=>$candidad,
				"rem_cat"=>$this->get("cbocategory"),
				"rem_name"=>$this->get("txname"),
				"rem_DOB"=>$this->get("cbdob"),
				"rem_nationalitys"=>$this->get("txtnation"),
				"rem_email"=>$this->get("txtemail"),
				"rem_tel"=>$this->get("txtphone"),
				"rem_other_tel"=>$this->get("txtother"),
				"rem_add"=>$this->get("txtadd"),
				"rem_city"=>$this->get("txtcity"),
				"rem_province"=>$this->get("txtstate"),
				"rem_code"=>$this->get("txtzip"),
				"rem_country"=>$this->get("txtcountry"),
				"rem_educate"=>$this->get("cbEdu"),
				"rem_edu_sum"=>$this->get("txtsumm"),
				"rem_experience"=>$this->get("txtwork"),
				"rem_experience_y"=>$this->get("cbYwork"),
				"rem_start"=>$this->get("txtavail"),
				"rem_salary"=>$this->get("txtsalary"),
				"rem_location"=>$this->get("location"),
				"rem_position"=>$this->get("position"),
				"rem_note"=>$this->get("txtnote"),
				"rem_hit"=>$version,
				"rem_modify"=>date("Y-m-d H:i:s")
		),array("can_id="=>$this->get("id")));
		$this->redirect(array("resume"=>"editcv","id"=>$this->get("id")));
	}
	public function view(){
		$resume = $this->loadModel("Resume");
		$record = $resume->findAsObject(array("can_id="=>$this->can_session["id"]));
		$gallery = $this->loadModel( "Gallery");
		if( is_object($record) && $record->rem_attach != "" ){
			$record -> rem_attach = $gallery->findAsObject(array("id="=>$record->rem_attach));
			$this->set(array("row"=>$record));
		}
		$this->render("view");
	}

	/* Modified by Noeur Phireak
	 * Date 08-April-2014
	*/
	public function download(){
		$resume = $this->loadModel("Resume");
		$gallery = $this->loadModel( "Gallery");
		$viewresume = $this->loadModel("ViewResume");

		/* Not only use by candidate,This function we also use by employer when they
		 * want to download resume if we check on sessionid of candidate isn't the right concept we should check it with resume id
		$record = $resume->findAsObject(array("can_id="=>$this->can_session["id"]));
		*/
		$record = $resume->findAsObject(array("id="=>$this->get("rem_id")));
		if(is_object($record)&&$record->rem_attach!=""){
			$record->rem_attach = $gallery->findAsObject(array("id="=>$record->rem_attach));
			$this->set(array("row"=>$record));
		}
		if(is_object($record->rem_attach)&&Basic::fileExist(REAL_PATH.$record->rem_attach->location)){
			$view_record = $viewresume->findAsObject(array("rem_id="=>$this->get("rem_id")));
			//update download field in viewresume table to note that this resume was download
			if(!in_array($this->emp_session['id'], explode(",",$view_record->download))){
				$emp_id = isset($this->emp_session['id'])?$this->emp_session['id']:NULL;
				$download = $view_record->download!=NULL?$view_record->download.",".$emp_id:$emp_id;
				$viewresume->update(array("download"=>$download),array("rem_id="=>$this->get("rem_id")));
			}
			header ('Content-type: '.$record->rem_attach->type );
			header('Content-Disposition:attachment; filename='.$record->rem_attach->name);
			$fh = fopen(REAL_PATH.$record->rem_attach->location, 'rb');
			while (!feof($fh)){
				$chunk = fread($fh, 1024);
				echo $chunk;
			}
			fclose($fh);
		}else{
			Basic::eco("Note : This file doesn't exited !");
			//$this->refresh(array("resume"=>"view"),array(),3);
		}
	}
	public function Editrem(){
		$resume = $this->LoadModel("Resume");
		$gallery= $this->loadModel("Gallery");
		$category = $this->loadModel("Categorie");
		$row = $resume->getResumeWithUser($this->can_session["id"]) ;
		$profilePhoto = !empty($row )&&is_object($row->rem_uploadImg)?ROOT.$row->rem_uploadImg->location:"";
		$this->set(array("profile_picture"=>$profilePhoto));
		$this->set(array("row"=>$row));
		$this->set(array("exp_years"=>$category->ExYear(133)));
		$this->set(array("edu_degrees"=>$category->SelectQu(138)));
		$this->set(array("locations"=>$category->SelectQu(1)));
		$this->set(array("positions"=>$category->SelectQu(150)));
		$this->set(array("postcodes"=>$category->SelectQu(180)));
		$this->set(array("nationalities"=>$category->SelectQu(34)));
		$this->set(array("categories"=>$category->SelectQu(23)));
                $this->set(array("category"=>$category->SelectQu(23)));
		$this->set(array("code"=>$resume->SelectQu(180)));
		$this->set(array("gender"=>$resume->SelectQu(219)));
		$this->set(array("layout"=>"resume"));
		$this->render(array("candidate"=>"admin"));
	}
	/*
	 *@Developer: Mr.Phan Chamnan and Mr.Dim sidet
	*@Create Date:26-March-2014
	*@Return new category
	*/
	public function addNewCategory(){
		
		$resumes = $this->loadModel("Resume");
		$category = $this->loadModel("Category");
		/* starting of catch value from resume form  */
		$catefuncRecord=trim($this->get("cbocategory"));
		$workexpienceRecord=trim($this->get("cbYwork"));
		$educationRecord=trim($this->get("cbEdu"));
		$locationRecord=trim($this->get("location"));
		$countryRecord=trim($this->get("txtcountry"));
		$zipcodeRecord=trim($this->get("txtzip"));
		/* ending of catch value from resume form  */
		/* staring of compare input select where name store id in function,education,experience,and location */
		$job_clasification = $resumes->getCategoryId($catefuncRecord);
		$cbEdu = $resumes->getCategoryId($educationRecord);
		$cbYwork = $resumes->getCategoryId($workexpienceRecord);
		$location = $resumes->getCategoryId($locationRecord);
		$country = $resumes->getCategoryId($countryRecord);
		$zipcode = $resumes->getCategoryID($zipcodeRecord);
		/* ending of compare input select where name store id in in function,education,experience,and location */
		/* staring of select category in function,education,experience,and location with searchset field */
		$searchSet_job_classify = $resumes->getSearchSet(23);
		$searchSet_education = $resumes->getSearchSet(138);
		$searchSet_experience = $resumes->getSearchSet(133);
		$searchSet_location = $resumes->getSearchSet(1);
		$searchSet_country = $resumes->getSearchSet(34);
		$searchSet_zipcode = $resumes->getSearchSet(180);
		
		$l_position = strtolower($this->get("all_position"));
		$all_position = explode(":",trim($l_position));
		$counts_pos = count($all_position);
		for ($i=0;$i<$counts_pos;$i++){
			//$all_degrees = $resumes->getCategoryId($all_degree[$i]);
			if(!$resumes->checkCategory($all_position[$i]) && !empty($all_position[$i])){
				$position = $category->save(array("name"=>$all_position[$i],"parent_id"=>"23"));
				$category->update(array("search_set"=>$searchSet_education->search_set.",".$position->id),array("id="=>"23"));
			}else {
		
			}
		}
		
		$l_degree = strtolower($this->get("txt_all_degree"));
		$all_degree = explode(":",trim($l_degree));
		$counts = count($all_degree);
		for ($i=0;$i<$counts;$i++){
			//$all_degrees = $resumes->getCategoryId($all_degree[$i]);
			if(!$resumes->checkCategory($all_degree[$i]) && !empty($all_degree[$i])){
				$degree = $category->save(array("name"=>$all_degree[$i],"parent_id"=>"138"));
				$category->update(array("search_set"=>$searchSet_education->search_set.",".$degree->id),array("id="=>"138"));
			}else {
				
			}
		}
		
		$l_major = strtolower($this->get("txt_all_major"));
		$all_major = explode(":",trim($l_major));
		$counts_major = count($all_major);
		for ($i=0;$i<$counts_major;$i++){
			//$all_degrees = $resumes->getCategoryId($all_degree[$i]);
			if(!$resumes->checkCategory($all_major[$i]) && !empty($all_major[$i])){
				$major = $category->save(array("name"=>$all_major[$i],"parent_id"=>"23"));
				$category->update(array("search_set"=>$searchSet_education->search_set.",".$major->id),array("id="=>"23"));
			}else {
		
			}
		}

		if(!$resumes->checkCategory(strtolower($zipcodeRecord)) && !empty($zipcodeRecord)){
			$zipcode = $category->save(array("name"=>strtolower($zipcodeRecord),"parent_id"=>"180"));
			$category->update(array("search_set"=>$searchSet_zipcode->search_set.",".$zipcode->id),array("id="=>"180"));
			$resumes->update(array("rem_code"=>$zipcode->id),array("can_id="=>$this->get("id")));
		}else {
			$resumes->update(array("rem_code"=>$zipcodeRecord),array("can_id="=>$this->get("id")));
		}
		/* staring of select category in function,education,experience,and location with searchset field  */
		/*staring of add new category if it is not in job clasification category*/
		if(!$resumes->checkCategory(strtolower($catefuncRecord)) && !empty($catefuncRecord)){
			$job_clasify = $category->save(array("name"=>strtolower($catefuncRecord),"parent_id"=>"23"));
			$category->update(array("search_set"=>$searchSet_job_classify->search_set.",".$job_clasify->id),array("id="=>"23"));
			$resumes->update(array("rem_cat"=>$job_clasify->id),array("can_id = "=>$this->get("id")));
		}else{
			$resumes->update(array("rem_cat"=>$job_clasification),array("can_id = "=>$this->get("id")));
		}
		/*ending of add new category if it is not in job clasification category*/
		/*starting of add new category if it is not in education category*/
		if(!$resumes->checkCategory(strtolower($educationRecord)) && !empty($educationRecord)){
			$education = $category->save(array("name"=>strtolower($educationRecord),"parent_id"=>"138"));
			$category->update(array("search_set"=>$searchSet_education->search_set.",".$education->id),array("id="=>"138"));
			$resumes->update(array("rem_educate"=>$educationRecord),array("can_id = "=>$this->get("id")));
		}else{
			$resumes->update(array("rem_educate"=>$educationRecord),array("can_id = "=>$this->get("id")));
		}
		/*ending of add new category if it is not in job clasification category*/
		/*starting of add new category if it is not in country category*/
		if(!$resumes->checkCategory(strtolower($countryRecord)) && !empty($countryRecord)){
			$country = $category->save(array("name"=>strtolower($countryRecord),"parent_id"=>"34"));
			$category->update(array("search_set"=>$searchSet_country->search_set.",".$country->id),array("id="=>"34"));
			$resumes->update(array("rem_country"=>$countryRecord),array("can_id = "=>$this->get("id")));
		}else {
			$resumes->update(array("rem_country"=>$countryRecord),array("can_id = "=>$this->get("id")));
		}
		/*ending of add new category if it is not in education category*/
		
		/*starting of add new category if it is not in  work experience category*/
		if(!$resumes->checkCategory(strtolower($workexpienceRecord)) && !empty($workexpienceRecord)){
			$experience = $category->save(array("name"=>strtolower($workexpienceRecord),"parent_id"=>"133"));
			$category->update(array("search_set"=>$searchSet_experience->search_set.",".$experience->id),array("id="=>"133"));
			$resumes->update(array("rem_experience_y"=>$workexpienceRecord),array("can_id = "=>$this->get("id")));
		}else{
			$resumes->update(array("rem_experience_y"=>$workexpienceRecord),array("can_id = "=>$this->get("id")));
		}
		/*ending of add new category if it is not in  work experience category*/
		/*starting of add new category if it is not in location category*/
		if(!$resumes->checkCategory(strtolower($locationRecord)) && !empty($locationRecord)){
			$locat = $category->save(array("name"=>strtolower($locationRecord),"parent_id"=>"1"));
			$category->update(array("search_set"=>$searchSet_location->search_set.",".$locat->id),array("id="=>"1"));
			$resumes->update(array("rem_location"=>$locationRecord),array("can_id = "=>$this->get("id")));
		}else{
			$resumes->update(array("rem_location"=>$locationRecord),array("can_id = "=>$this->get("id")));
		}
		/*ending of add new category if it is not in location category*/
	}
	public function saveEdit(){
		$work_experience_new = str_replace("undefined","",$this->get("work_experience"));
		$education_sum_new = str_replace("undefined","",$this->get("txtmore_education"));
		$resumes = $this->loadModel("Resume");
		$point = $this->loadModel("Point");
		$candidate = $this->loadModel("Candidate");
		
		$this->set(array("SelectY"=>$resumes->SelectQu(133)));
		$this->set(array("Select"=>$resumes->SelectQu(138)));
		$this->set(array("Location"=>$resumes->SelectQu(1)));
		$this->set(array("Position"=>$resumes->SelectQu(150)));
		$this->set(array("category"=>$resumes->SelectQu(23)));
		//check reference email does it existed on this record of resume or not ?
		$reference_record = $candidate->findAsObject(array("email="=>$this->get("txtReference")));
		$reference = isset($reference_record)&&is_object($reference_record)?$reference_record:"";
		
		//get point from table config
		$config = $this->loadModel("Config");
		$getConfig = $config->findAsObject(array("id="=>1));
		
		if(isset($_POST)&&$resumes->checkResume($this->can_session["id"])){
			//Modified by Mr. Phireak. this I have to modified according to who created it 
			$data = $resumes->findAsObject(array("can_id="=>$this->get("id")));
			$data =  isset($data)&&!empty($data)?$data:NULL;
			$record = $this->upload($this->can_session["id"],"data/pp",5);
			$fields = array(
					"rem_status"=>$this->get("rStatus"),
					"rem_cat"=>$this->get("cbocategory"),
					"rem_name"=>$this->get("txname"),
					"rem_DOB"=>$this->get("cbdob"),
					"rem_nationalitys"=>$this->get("txtnation"),
					"rem_add"=>$this->get("txtadd"),
					"rem_email"=>$this->get("txtemail"),
					"rem_tel"=>$this->get("txtphone"),
					"rem_other_tel"=>$this->get("phones"),
					"rem_gender"=>$this->get("cambogender"), 
					"rem_curent_add"=>$this->get("txthome").":".$this->get("txtstreet").":".$this->get("txtvillage").":".$this->get("txtcommune").":".$this->get("txttown").":".$this->get("txtcity"),
					//"rem_city"=>$this->get("txtcity"),
					//"rem_province"=>$this->get("txtstate"),
					"rem_code"=>$this->get("txtzip"),
					"rem_country"=>$this->get("txtcountry"),
					"rem_educate"=>$this->get("cbEdu"),
					"rem_edu_sum"=>$this->get("txtsumm"),
					"rem_experience"=>$this->get("txtwork"),
					"rem_experience_y"=>$this->get("cbYwork"),
					"rem_start"=>$this->get("txtavail"),
					"rem_salary"=>$this->get("txtsalary"),
					"rem_location"=>$this->get("location"),
					"rem_position"=>$this->get("txtposition"),
					"rem_note"=>$this->get("txtnote"),
					"reference"=>$this->get("txtReference"),
					"rem_experience_new"=>$work_experience_new,
					"rem_education_new"=>$education_sum_new,
					"rem_language"=>$this->get("languages"),
					"social_network"=>$this->get("fb").":".$this->get("gplus").":".$this->get("skype"),
					"rem_version"=>isset($data->rem_version)&&!empty($data->rem_version)?$data->rem_version+1:0 ,
					//"rem_hit"=>isset($data->rem_hit)&&!empty($data->rem_hit)?$data->rem_hit+1:0 ,
					"rem_modify"=>date("Y-m-d H:i:s"));
			if(!empty($record)){
				//delete photo
				$row = $resumes->getResumeWithUser($this->can_session["id"]) ;
				$gallery = $this->loadModel("Gallery");
				if($row->rem_uploadImg!=Null || $row->rem_uploadImg!=false){
					$gallery->deletephoto(array(is_object($row->rem_uploadImg)?$row->rem_uploadImg->id:$row->rem_uploadImg),true);
				}
				$fields["rem_uploadImg"]=$record[0];
			}	
			//check all field
			$allFields = $resumes->findAsObject(array("can_id="=>$this->can_session["id"]));
			$empty_field = 0;
			$skip_field = array("rem_other_tel","rem_approve","list_on_web","expired","rem_edu_sum","rem_experience","rem_note","rem_identify","rem_approve","status","cv_status_view","social_network","rem_city","rem_province","rem_attach","reference");
			foreach ($allFields as $key => $val){
				if(!in_array($key, $skip_field)){
					if($val=="" || $val=="NULL"){
						$empty_field+=1;
					}
				}
			}
			if($empty_field == 0){ //It mean that all requirement field was fill up
				$point = $this->loadModel("Point");
				$point_record = $point->findAsObject(array("can_id="=>$this->can_session["id"]));
				if(!is_object($point_record)&&empty($point_record)){
					$point->save(array("resume"=>$getConfig->completed_cv,"can_id"=>$this->can_session["id"],"created"=>date("Y-m-d H:i:s"),"modified"=>date("Y-m-d H:i:s")));
				}
			}
			
			$this->addNewCategory();//add new if category input in resume form is not in db and update it to resume table
			$resumes->update($fields,array("can_id="=>$this->get("id")));
			
			//update introduce point for reference email
			$reference_update = $point->findAsObject(array("can_id="=>$reference->id));
			$reference_update = isset($reference_update)&&!empty($reference_update)?$reference_update:"";
			$reference_resume = $resumes->findAsObject(array("can_id="=>$reference->id));
			if($reference_resume->rem_attach!=NULL&&!empty($reference_resume->rem_attach)){
				if($data->reference==NULL || ($data->reference!=$reference->email)){ // if field reference in resume has been set no need to update
					$result = $point->update(array("introduce"=>($reference_update->introduce + $getConfig->introduce_friend)),array("can_id="=>$reference->id));
				}
			}
			
			//Send mail to the one who follow this resume
			$membership = $this->loadModel("Membership");
			$employer = $this->loadModel("Employer");
			$getUserIds = $membership->getObject(array("*"),array("resume_id="=>$allFields->id));
			foreach($getUserIds as $getUserId){
				$getMails[] = $employer->findObject(array("id="=>$getUserId->user_id));
			}
			$pid = $allFields->id;
			//Send mail to Employer when candidate update Resume
			$str = "Candidate who was followed by you.<br/> Now they have some change on their resume<br/>";
			$str .="If you want to see some change on resume, please click this link <a href='". SERVER.ROOT ."index.php/resume/detailcandidat/pid:$pid'>click here</a>";
			ob_start();
			//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
			Import::util('class.phpmailer');
			//the true param means it will throw exceptions on errors, which we need to catch
			$mail = new PHPMailer(true);
			//telling the class to use SMTP
			$mail->IsSMTP();
			try {
				// SMTP server
				$mail->Host = "mail.hrcambodia.com";
				// enables SMTP debug information (for testing),  show debug : SMTPDebug  = 2,  Hide debug : SMTPDebug  = 1
				$mail->SMTPDebug = 1;
				// enable SMTP authentication
				$mail->SMTPAuth = true;
				// set the SMTP port for the MY OWN DOMAIN server
				$mail->Port = 26;
				// SMTP account username
				$mail->Username = "noreply@hrcambodia.com";
				// SMTP account password
				$mail->Password = "pwd*123456";
				foreach($getMails as $getMail){
					$email_address = filter_input(INPUT_GET, $getMail->email, FILTER_VALIDATE_EMAIL);
					if (!$email_address) {
						$mail->SetFrom('noreply@hrcambodia.com', 'HRCambodia.com');
						$mail->AddAddress($getMail->email,$getMail->email);
						$mail->AddReplyTo('admin@hrcambodia.com', 'HRCambodia.com');
						$mail->Subject = "HRCambodia Alert Changing Resume";
						// optional - MsgHTML will create an alternate automatically
						$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
						$mail->MsgHTML("<h3>HRCambodia Alert Changing Resume</h3>" . $str . "<br/>");
						$mail->Send();
					} else {
						//echo 'Email is invalid...';
						break;
					}
				}
			} catch (phpmailerException $e) {
				//Pretty error messages from PHPMailer
				echo $e->errorMessage();
			} catch (Exception $e) {
				//Boring error messages from anything else!
				echo $e->getMessage();
			}
			$this->redirect(array("resume"=>"editcv"));
		}else{
			//save new resume
			$record=$this->upload($this->can_session["id"],"data/pp",5);
			$record = $resumes->save(array(
					"rem_uploadImg"=>!empty($record)?$record[0]:0,
					"can_id"=>$this->can_session["id"],
					"rem_cat"=>$this->get("cbocategory"),
					"rem_status"=>$this->get("rStatus"),
					"rem_name"=>$this->get("txname"),
					"rem_DOB"=>$this->get("cbdob"),
					"rem_nationalitys"=>$this->get("txtnation"),
					"rem_email"=>$this->get("txtemail"),
					"rem_tel"=>$this->get("txtphone"),
					"rem_gender"=>$this->get("txgender"),
					"rem_other_tel"=>$this->get("phones"),
					"rem_add"=>$this->get("txtadd"),
					"rem_curent_add"=>$this->get("txthome").":".$this->get("txtstreet").":".$this->get("txtvillage").":".$this->get("txtcommune").":".$this->get("txttown").":".$this->get("txtcity"),
					"rem_city"=>$this->get("txtcity"),
					"rem_province"=>$this->get("txtstate"),
					"rem_code"=>$this->get("txtzip"),
					"rem_country"=>$this->get("txtcountry"),
					"rem_educate"=>$this->get("cbEdu"),
					"rem_edu_sum"=>$this->get("txtsumm"),
					"rem_experience"=>$this->get("txtwork"),
					"rem_experience_y"=>$this->get("cbYwork"),
					"rem_start"=>$this->get("txtavail"),
					"rem_salary"=>$this->get("txtsalary"),
					"rem_location"=>$this->get("location"),
					"rem_position"=>$this->get("txtposition"),
					"rem_note"=>$this->get("txtnote"),
					"rem_createDate"=>date("Y-m-d H:i:s"),
					"rem_hit"=>1,
					"rem_experience_new"=>$this->get("work_experience"),
					"rem_education_new"=>$this->get("txtmore_education"),
					"reference"=>$this->get("txtReference"),
					"rem_modify"=>date("Y-m-d H:i:s")
			));
			//update introduce point for reference email
			$reference_update = $point->findAsObject(array("can_id="=>$reference->id));
			$reference_update = isset($reference_update)&&!empty($reference_update)?$reference_update:"";
			$reference_resume = $resumes->findAsObject(array("can_id="=>$reference->id));
			if($reference_resume->rem_attach!=NULL&&!empty($reference_resume->rem_attach)){
				if($data->reference==NULL || ($data->reference!=$reference->email)){ // if field reference in resume has been set no need to update
					$result = $point->update(array("introduce"=>($reference_update->introduce + $getConfig->introduce_friend)),array("can_id="=>$reference->id));
				}
			}
			$this->addNewCategory();//add new if category input in resume form is not in db and update it to resume table
			//check all field
			$allFields = $resumes->findAsObject(array("can_id="=>$this->can_session["id"]));
			$empty_field = 0;
			$skip_field = array("rem_other_tel","rem_approve","list_on_web","expired","rem_edu_sum","rem_experience","rem_note","rem_identify","rem_approve","status","cv_status_view","social_network","rem_city","rem_province","rem_attach","reference");
			foreach ($allFields as $key => $val){
				if(!in_array($key, $skip_field)){
					if($val=="" || $val=="NULL"){
						$empty_field+=1;
					}
				}
			}
			if($empty_field == 0){ //It mean that all requirement field was fill up
				$point = $this->loadModel("Point");
				$point_record = $point->findAsObject(array("can_id="=>$this->can_session["id"]));
				if(!is_object($point_record)&&empty($point_record)){
					$point->save(array("resume"=>$getConfig->completed_cv,"can_id"=>$this->can_session["id"],"created"=>date("Y-m-d H:i:s"),"modified"=>date("Y-m-d H:i:s")));
				}
			}
			$this->redirect(array("resume"=>"editcv"));
		}/* else{
			echo "VIEWRESUME";
			exit();
			$this->set(array("row"=>$this->findObject(array("id="=>$this->get("id")))));
			$this->layout("editcv");
			if (!empty($record)) {
				// delete photo
				$row = $resumes -> getResumeWithUser($this->can_session["id"]);
				if ($row) {
					$gallery = $this -> loadModel("Gallery");
					$gallery -> deletephoto(array(is_object($row -> rem_uploadImg) ? $row -> rem_uploadImg -> id : $row -> rem_uploadImg), true);
				}
			}
		} */
	}

	public function upload($user_id,$folder="data",$size=5){
		Import::util("FileUpload");
		if(!Basic::fileExist($folder))Basic::createFolder($folder);
		$gallery = $this->loadModel("Gallery");
		$infos=FileUpload::checkFileUpload($folder);
		$helper = true;
		$ids=array();
		foreach($infos as $info ){
			if($info["error"]["number"]==0){
				if(($record=$gallery->savephoto(array(
						"uid"=>$user_id,
						"gname"=>Session::get("candidate_name"),
						"name"=>$info["name"],
						"location"=>"",
						"type"=>$info["type"],
						"size"=>$info["size"],
						"d_w"=>$info["dimension"]["width"],
						"d_h"=>$info["dimension"]["height"],
						"created"=>date("Y-m-d H:s:i"),
						"modified"=>date("Y-m-d H:s:i"))))!==false){
						$gallery->update(array("location"=>$folder."/".$record->id.".".$info["ext"]),array("id="=>$record->id));
						$ids[]=$record->id;
						FileUpload::uploadFile($info["control"],$record->id.".".$info["ext"],5,$folder);
				}else{
					Basic::eco("<br/>There is an unexpected error occured during upload file.<br/>");
					Basic::pr($info);
					$help=false;
				}
			}
			else{
				// check error
			}
		}
		return !empty($ids)?$ids:false;
	}

	//function upload attachment file (cv /resume)
	public function funFileUpload(){
		Import::util("FileUpload");
		$user_id = $this->can_session["id"];
		$user = Session::get("candidate_name"); 
		$folder = "data/cv";
		if(!Basic::fileExist($folder))Basic::createFolder($folder);
		$gallery = $this->loadModel("Gallery");
		$resume = $this->loadModel("Resume");
		$infos=FileUpload::checkFileUpload($folder);
		$helper = true;
		$info=$infos[0];
		//Check all resume fields
		$allFields = $resume->findAsObject(array("can_id ="=>$this->can_session["id"]));
		//get point from table config
		$config = $this->loadModel("Config");
		$getConfig = $config->findAsObject(array("id="=>1));
		
		if($info["error"]["number"]==0){
			if($allFields->rem_attach == NULL){ 
				if(($record=$gallery->savephoto(array("uid"=>$user_id,"gname"=>$user,"name"=>$info["name"],"location"=>"","type"=>$info["type"],"size"=>$info["size"],"d_w"=>$info["dimension"]["width"],"d_h"=>$info["dimension"]["height"],"created"=>date("Y-m-d H:i:s"),"modified"=>date("Y-m-d H:i:s"))))!==false){
					if($allFields){
						$resume->edit(array("rem_attach"=>$record->id),array("can_id = "=>$this->can_session["id"]));
						//new feature of point for candidate
						$point = $this->loadModel("Point");
						$point_record = $point->findAsObject(array("can_id="=>$this->can_session["id"]));
						if(!is_object($point_record)&&empty($point_record)){
							$point->save(array("resume"=>$getConfig->completed_cv,"can_id"=>$this->can_session["id"],"created"=>date("Y-m-d H:i:s"),"modified"=>date("Y-m-d H:i:s")));
						}
					}else{
						if($allFields->can_id != $this->can_session["id"]){
							$resume->save(array("rem_attach"=>$record->id,"can_id"=>$this->can_session["id"]));
						}
					}
					$gallery->update(array("location"=>$folder."/".$record->id.".".$info["ext"]),array("id = "=>$record->id));
					FileUpload::uploadFile($info["control"],$record->id.".".$info["ext"],5,$folder);
					//echo "file successfully uploaded";
					$style="<body style='margin:0; padding:0;'><img src=" . Import::link("img/approved.png") . " style='margin-top:-10px; padding:0px 7px;' /> ";
					print_r($style . " file successfully uploaded</body> " );
				}else{
					Basic::eco("<br/>There is an unexpected error occured during upload file.<br/>");
					Basic::pr($info);
					$help=false;
				}
			}else{
				$image = $gallery->findAsObject(array("id="=>$allFields->rem_attach));
				if( file_exists(REAL_PATH.$image->location))Basic::deleteFile(REAL_PATH.$image->location);
				if(($record=$gallery->update(array("name"=>$info["name"],"location"=>$folder."/".$image->id.".".$info["ext"],"type"=>$info["type"],"size"=>$info["size"],"d_w"=>$info["dimension"]["width"],"d_h"=>$info["dimension"]["height"],"modified"=>date("Y-m-d H:i:s")),array("id = "=>$image->id)))!==false){
					FileUpload::uploadFile($info["control"],$image->id.".".$info["ext"],5,$folder);
					//echo "file successfully uploaded";
					$style="<body style='margin:0; padding:0;'><img src=" . Import::link("img/approved.png") . " style='margin-top:-10; padding:0 7;' /> ";
					print_r($style . " file successfully uploaded</body> ");
				}else{
					Basic::eco("<br/>There is an unexpected error occurred during upload file.<br/>");
					Basic::pr($info);
					$help=false;
				}
			}
		}else{
			//	echo "error uploading file";
			$style="<body style='margin:0; padding:0;'><img src=" . Import::link("img/rejected.png") . " style='margin-top:-10; padding:0 7;' align='middle'/> ";
			print_r($style . " error uploading file </body> ");
		}
	}
	/**
	 *  Modified by Mr. Phireak
	 */
	public function detailCan() {
		//this process used for mail link view from employer 
		$emp_id = $this->get("emp");
		if(isset($emp_id)&&!empty($emp_id)){
			$employer = $this->loadModel("Employer");
			$user = $this->loadModel("User");
			$emp_record = $employer->findObject(array("id="=>$emp_id));
			if(is_object($emp_record)&&!empty($emp_record)){
				$sessionId = $user->getSessionId($emp_record->username,$_SERVER['REMOTE_ADDR']);
				Session::set("employer" ,array(
					"id"=>$emp_record->id,
					"session"=> $sessionId ,
					"user" => $emp_record->username
				));
			}
		}
		/* End this Process */
		$membership = $this->loadModel("Membership");
		$rem = $this -> loadModel("SaveResume");
		$resumes = $this -> loadModel("Resume");
		$employer = $this->loadModel("Employer");
		$applyjob = $this->loadModel("Job");
		$category = $this->loadModel("Categorie");
		$notiApply = $this->loadModel("NotiApplie");
		$employer = $this->loadModel("Employer");
		$gallery = $this ->loadModel("Gallery");
		$emp_info = $employer->findObject(array("id="=>$this->emp_session["id"]));
		$this->set(array("employer"=>$emp_info));
		$this->set(array("emp_imgs"=>$gallery->findObject(array("id="=>$emp_info->img_id))));

		$viewresume = $this->loadModel("ViewResume");
		$remId = $viewresume->findAsObject(array("rem_id="=>$this->get("pid")));
		//check does employer ever view this resume before ?
		if(in_array($this->emp_session['id'],explode(",",@$remId->view))){
			$this->set(array("view_cv"=>"fullview"));
			//update view resume information depending on resume id
			$viewresume->update(array("last_view"=>$this->emp_session['id'],"view_date"=>date("Y-m-d H:i:s")),array("rem_id="=>$this->get("pid")));
			//get resume field value from employer , To see which's resume which has been view
			$resumesId = $employer->findAsObject(array("id="=>$this->emp_session['id']));
			// check resume id does it exist on resumes field in Employer table
			if(!in_array($this->get("pid"),explode(",",$resumesId->resumes))){
				$remIds = $resumesId->resumes==NULL?$this->get("pid"):$resumesId->resumes.",".$this->get("pid");
				//add more resume id in resumes field in employer table to note that all these resumes was view by them
				$employer->update(array("resumes"=>$remIds),array("id="=>$this->emp_session["id"]));
			}
		}

		//update hit on resume
		$recordNoti = $notiApply->findAsObject(array("id="=>$this->get("appid"),"status="=>"1"));
		if(is_object($recordNoti)){
			$resume_obj = $resumes->findAsObject(array("id="=>$this->get("pid")));
			//not send mail
		}else{
			$notiApply->Update(array("status"=>"1"),array("id="=>$this->get("appid")));
			$resume_obj = $resumes->findAsObject(array("id="=>$this->get("pid")));
			$rem_hit = is_object($resume_obj)?$resume_obj->rem_hit + 1:1;
			$resumes->update(array("rem_hit"=>$rem_hit),array("id="=>$this->get("pid")));
			//Alert mail to candidat to tell that have an employer view or read it
			$recordEmp = $employer->findAsObject(array("id = "=>$this->emp_session["id"]));
			$str = "Your Resume  have an campany read it!<br/>";
			$str .= "Name : " .$recordEmp->firstname ." ".$recordEmp->lastname ."<br/>";
			$str .= "Email : " .$recordEmp->email. "<br/>";
			$str .= "Company : " .$recordEmp->company_name."<br/>";
			ob_start();
			//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
			Import::util('class.phpmailer');
			//the true param means it will throw exceptions on errors, which we need to catch
			$mail = new PHPMailer(true);
			//telling the class to use SMTP
			$mail->IsSMTP();
			try {
				// SMTP server
				$mail->Host = "mail.atmos-techno.com";
				// enables SMTP debug information (for testing),  show debug : SMTPDebug  = 2,  Hide debug : SMTPDebug  = 1
				$mail->SMTPDebug = 1;
				// enable SMTP authentication
				$mail->SMTPAuth = true;
				// sets the SMTP server
				$mail->Host = "mail.atmos-techno.com";
				// set the SMTP port for the MY OWN DOMAIN server
				$mail->Port = 26;
				// SMTP account username
				$mail->Username = "demo@atmos-techno.com";
				// SMTP account password
				$mail->Password = "demo*123456";
				//$mail->AddAddress('info@atmos-techno.com', 'Atmosphere Technology Co.,Ltd');
				$mail->AddAddress('physopheak10@gmail.com', '');
				//$mail->AddAddress('phonpisey23@gmail.com','');
				$email_address = filter_input(INPUT_GET, $recordEmp->email, FILTER_VALIDATE_EMAIL);
				if (!$email_address) {
					$mail->SetFrom('demo@atmos-techno.com', 'HRCambodia');
					// $mail->AddAddress('info@atmos-techno.com', 'Atmosphere Technology Co.,Ltd');
					$mail->AddAddress($recordEmp->email, ' ');
					//$mail->AddAddress('phonpisey23@gmail.com','');
					$mail->AddReplyTo('demo@atmos-techno.com', 'sales@hrcambodia.com');
					$mail->Subject = "Employer have read your Resume";
					// optional - MsgHTML will create an alternate automatically
					$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
					$mail->MsgHTML("<h3>Employer Information</h3>" . $str . "<br/>");
					//$mail->Send();
				} else {
					//echo 'Email is invalid...';
					break;
				}
			} catch (phpmailerException $e) {
				//Pretty error messages from PHPMailer
				echo $e->errorMessage();
			} catch (Exception $e) {
				//Boring error messages from anything else!
				echo $e->getMessage();
			}
		}
		$this -> set(array("Getallcate" => $category->getCategoriesAsArray()  ));
		$this -> set(array("row" => $resume_obj ));
		$this -> set(array("layout" => "detailcv"));
		$this -> render(array("employer" => "admin"));
	}
	/*Mr. Phireak */
	public function buyResume(){
		$membership = $this->loadModel("Membership");
		$config = $this->loadModel("Config");
		$employer = $this->loadModel("Employer");
		$gallery = $this ->loadModel("Gallery");
		$emp_info = $employer->findObject(array("id="=>$this->emp_session["id"]));
		$this->set(array("employer"=>$emp_info));
		$this->set(array("emp_imgs"=>$gallery->findObject(array("id="=>$emp_info->img_id))));
		$configuration = $config->findAsObject(array("id="=>1));
		$point = $membership->findAsObject(array("user_id="=>$this->emp_session["id"],"sub_type="=>"Employer"));
		$resume_id = $this->get("pid");
		if($point->posting_point!=0&&$point->posting_point>=$configuration->buy_resume){
			$saveresume = $this->loadModel("SaveResume");
			$viewresume = $this->loadModel("ViewResume");
			$resume = $this->loadModel("Resume");
			//reduce posting point of employer when they bought to view full resume information
			$membership->update(array("posting_point"=>($point->posting_point-$configuration->buy_resume)),array("user_id="=>$this->emp_session["id"],"sub_type="=>"Employer"));
			//get resume view information
			$rem_record = $viewresume->findAsObject(array("rem_id="=>$resume_id));
			//check if the resume id has been save before , and then just update record depending on resume id
			if($rem_record->rem_id==$resume_id){
				$viewresume->update(array(
						"view"=>$rem_record->view.",".$this->emp_session["id"],
						"buy"=>$rem_record->view.",".$this->emp_session['id'],
						"last_view"=>$this->emp_session['id'],
						"view_date"=>date("Y-m-d H:i:s"))
						,array("rem_id="=>$resume_id));
			}else{
				//save new viewresume record
				$viewresume->save(array(
						"rem_id"=>$this->get("pid") ,
						"view"=>$this->emp_session['id'] ,
						"buy"=>$this->emp_session['id'] ,
						"last_view"=>$this->emp_session['id'] ,
						"view_date"=>date("Y-m-d H:i:s")
				));
			}
			//$this->set(array("Getallcate"=>$saveresume->SelectC()));
			//$this->set(array("row"=>$resume->getResumeWithId($this->get("pid"))));
			//$this->set(array("layout"=>"displaycv"));
			//$this->render(array("employer"=>"admin"));
		}else{
			//Redirect to order page if no point
			echo "no_point";
			//$this->redirect(array("package"=>"displayfront"));
		}
	}
}
?>
